import com.irisking.ikaisdk.IKAI1000SDK;
import com.irisking.ikaisdk.dataStruct.CommandResp;
import com.irisking.ikaisdk.eventListener.ConnectEventListener;
import com.irisking.ikaisdk.eventListener.DisConnectEventListener;
import com.irisking.ikaisdk.handler.AckCallBack;

import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 启动函数
 * @author admin
 *
 */
public class TestServerMain {
	static String  sn_connected ;

	@SuppressWarnings("resource")
	public static void main(String[] args) throws IOException {
		IKAI1000SDK sdk = new IKAI1000SDK();
		sdk.initServer(7788);

		sdk.eventManager.addEventListener(new DisConnectEventListener() {
			@Override
			public void invoke(String sn, Date time) {
				System.out.println("设备离线，sn:" + sn + ", time:" + time.toString());
			}
		});
		sdk.eventManager.addEventListener(new ConnectEventListener() {
			@Override
			public void invoke(String sn, String ip, String mac, Date connect_time, String version, String server_id, long timestamp, AckCallBack connectEventCallBack) {
				connectEventCallBack.call(sn,timestamp,0,"");
				sn_connected = sn;
				System.out.println("设备连接，sn:" + sn + ", connect_time:" + connect_time.toString());
			}
		});

		try {
			TimeUnit.SECONDS.sleep(80);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		CommandResp resp = sdk.netCommand.OpenDoor(sn_connected,"1122334455");
		System.out.println("Open Door Command  execute，code:" + resp.getCode() + ", message:" + resp.getMessage());


		System.in.read();
	}






}

